import { createWebHistory, createRouter } from "vue-router";
import homePage from "../pages/homePage.vue";
import home from "../pages/home.vue";
import health from "../pages/health.vue";
import inquiry from "../pages/inquiry.vue";
import my from "../pages/my.vue";
import member from "../pages/member.vue";
import searchpage from "../pages/Searchpage.vue";
import login from "../pages/Login.vue";
import interrogation from "../pages/interrogation.vue";
import consultationDetails from "../pages/consultationDetails.vue";
import set from "../pages/set.vue";
import medical from "../pages/medical .vue";
import goregister from "../pages/goregister.vue"
import entire from "../pages/entire.vue";
import chat from "../pages/chat.vue";
import detail from '../pages/detail.vue';
import coupon from '../pages/coupon.vue';
import interrogationSearch from '../pages/interrogationSearch.vue'
import healthyDetails from '../pages/healthyDetails.vue';
import askMoreQuestions from '../pages/askMoreQuestions.vue';
import { showFailToast } from 'vant';
import Numbercenter from "../pages/Numbercenter.vue";
import collect from "../pages/collect.vue";
import register from '../pages/register.vue'
import mes from '../pages/mes.vue'
import screen from "../pages/screen.vue";
import accountset from "../pages/accountset.vue";
import carDetail from "../pages/carDetail.vue";
import car from "../pages/car.vue"
import cooperate from "../pages/cooperate.vue"
import fitness from "../pages/fitness.vue"
import record from "../pages/record.vue"
import VideoPlayer from "../pages/VideoPlayer.vue";
import Pneumonia from "../pages/Pneumonia.vue"
import money from "../pages/money.vue"
import comment from "../pages/comment.vue"
import giftGiving from "../pages/giftGiving.vue"
import forgetPassword from "../pages/forgetPassword.vue"
import editName from "../pages/editName.vue"
import consultationSum from "../pages/consultatioSum.vue"
import Redeem from "../pages/Redeem.vue";
import consultationSumone from "../pages/consultatioSumone.vue";
import turntable from "../pages/turntable.vue";
import scratchcard from "../pages/scratchcard.vue";
import homeCity from "../components/home/homeCity.vue";
import thirdclass from '../pages/thirdClass.vue'
import choice from "../pages/choice.vue";
import settle from "../pages/settle.vue";
import homeorder from '../components/home/homeorder.vue';
import Shipin from "../pages/Shipin.vue";
import customer from "../pages/customer .vue";
const routes = [
  { path: '/', redirect: '/home/home' },
  {path:'/login',component: login,title:'登录'},
  {path:'/medical',component: medical,title:'快速问诊'},
  {path:'/set',component: set,title:'设置'},
  {path:'/entire',component: entire,title:'乐城国际'},
  {path:'/chat',component: chat,title:'聊天室'},
  {path:'/coupon',component: coupon,title:'我的优惠卷'},
  {path:'/screen',component: screen,title:'微医甄选'},
  {path:'/accountset',component: accountset,title:'账号设置'},
  {path:'/cooperate',component: cooperate,title:'合作机构'},
  {path:'/fitness',component: fitness,title:'健康评估'},
  {path:'/record',component: record,title:'评估记录'},
  {path:'/Pneumonia',component: Pneumonia,title:'慢阻肺疾病评估'},
  {path:'/money',component: money,title:'我的钱包'},
  {path:'/turntable',component: turntable,title:'转盘抽奖'},
  {path:'/scratchcard',component:scratchcard,title:'刮刮乐'},
  {path:'/choice',component:choice,title:'精选服务'},
  {path:'/settle',component:settle,title:'商家入驻'},
  {path:'/customer',component:customer,title:'客服中心'},
  {
    path: "/home",
    component: homePage,
    title: "首页",
    children: [
      {
        path: "/home/home",
        component: home,
        title: "首页",
        meta: {
          KeepAlive: true
        }
      },
      {
        path: "/home/health",
        component: health,
        title: "健康",
      },
      {
        path: "/home/inquiry",
        component: inquiry,
        title: "问诊",
      },
      {
        path: "/home/my",
        component: my,
        title: "我的",
      },
      {
        path: "/home/member",
        component: member,
        title: "会员",
      },
      {
        path: "/home/searchpage",
        component: searchpage,
        title: "会员",
      },
    ],
  },
  {
    path: "/interrogation",
    component: interrogation,
    title: "专家问诊",
  },
  {
    path: "/consultationDetails",
    component: consultationDetails,
    title: "专家问诊详情页面",
  },
  {
    path: "/goregister",
    component: goregister,
    title: "去挂号",
  },
  {
    path: "/detail",
    component: detail,
    title: "首页tab健康详情页",
  },
  {
    path: "/interrogationSearch",
    component: interrogationSearch,
    title: "专家问诊搜索页面",
  },
  {
    path: "/NumberCenter",
    component: Numbercenter,
    title: "红包跳转会员中心页面",
  },
  {
    path: "/collect",
    component: collect,
    title: "收藏页面",
  },
  {
    path: "/healthyDetails",
    component: healthyDetails,
    title: "我的健康币",
  },
  {
    path: "/register",
    component: register,
    title: "注册",
  },
  {
    path: "/carDetail",
    component: carDetail,
    title: "首页好物推荐点击跳详情页",
  },
  {
    path: "/car",
    component: car,
    title: "购物车页面",
  },
  {
    path: "/askMoreQuestions",
    component: askMoreQuestions,
    title: "一病多问",
  },
  {
    path: "/mes",
    component: mes,
    title: "登录页隐私权政策详情",
  },
  {
    path: "/VideoPlayer",
    component: VideoPlayer,
    title: "登录页隐私权政策详情",
  },
  {
    path: "/comment",
    component: comment,
    title: "评论页",
  },
  {
    path: "/giftGiving",
    component: giftGiving,
    title: "送礼页",
  },
  {
    path: "/forgetPassword",
    component: forgetPassword,
    title: "忘记密码页面",
  },
  {
    path: "/editName",
    component: editName,
    title: "修改昵称",
  },
  {
    path: "/consultationSum",
    component: consultationSum,
    title: "医生支付页",
  },{
    path: "/Redeem",
    component: Redeem,
    title: "兑换优惠券页面",
  },
  {
    path: "/consultationSumone",
    component: consultationSumone,
    title: "医生支付页2",
  },
  {
    path: "/homeCity",
    component: homeCity,
    title: "城市选择页面",
  },
  {
    path: "/thirdclass",
    component: thirdclass,
    title: "三甲体检",
  },
  {
    path: "/homeorder",
    component: homeorder,
    title: "支付页",
  },
  {
    path: "/Shipin",
    component: Shipin,
    title: "点击图片跳转到视频页面",
  }
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});
export default router;
router.beforeEach((to, from, next) => {
  // 获取token
  const token = localStorage.getItem("token");
  // 判断要跳转的页面是否是登录页或注册页
  const isLoginPage = to.path === '/login';
  const isRegisterPage = to.path === '/register';
  const isforgetPassword = to.path === '/forgetPassword';
  const ismes = to.path === '/mes';
  if ((!token && !isLoginPage && !isRegisterPage && !ismes && !isforgetPassword)) {
    showFailToast('您还没登录，请先登录');
    next("/login");
  } else {
    next();
  }
})

